<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <button-counter></button-counter>
        <!-- 局部组件只能在父组件内部使用 -->
        <hello-world></hello-world>
        <daben-zhu></daben-zhu>
        <xiaoke-ai></xiaoke-ai>
    </div>
    <script src="../js/vue.min.js"></script>
    <script>
        // 全局组件定义
        Vue.component('button-counter', {
            data: function() {
                return {
                    count: 0
                }
            },
            template: '<button @click="handle">点击了{{count}}次</button>',
            methods: {
                handle: function() {
                    this.count++
                }
            }
        });

        // 局部组件注册
        var HelloWorld = {
            data: function() {
                return {
                    msg: 'HelloWorld'
                }
            },
            template: '<div>{{msg}}</div>'
        };
        var Dabenzhu = {
            data: function() {
                return {
                    msg: 'Dabenzhu'
                }
            },
            template: '<div>{{msg}}</div>'
        };
        var Xiaokeai = {
            data: function() {
                return {
                    msg: 'Xiaokeai'
                }
            },
            template: '<div>{{msg}}</div>'
        };
        // 其实也是个组件
        let vm = new Vue({
            el: "#app",
            data: {

            },
            // 局部组件挂载
            components: {
                'hello-world': HelloWorld,
                'daben-zhu': Dabenzhu,
                'xiaoke-ai': Xiaokeai
            }
        })
    </script>
</body>

</html>